import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

from common.untils import Lunta


class LunTahome():
    driver=""
    url=""
    def __init__(self):
        # 登陆状态url
        self.driver=Lunta.driver
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)



    def LTPuTest(self):
        self.driver.implicitly_wait(5)
        #点击发布帖子
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #选择板块
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad").click()
        #编辑框外置无法完成交互
        # 输入标题,若能交互则完成以下命令
        # self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("如何年薪百万")
        #self.driver.find_element(By.CSS_SELECTOR,"article_post_submit").click()
        # # Action链模拟点击
        # element = self.driver.find_element(By.XPATH, '//*[@id="article_post_submit"]')
        # ActionChains(self.driver).move_to_element(element).click().perform()
        # # 提示帖子内容不能为空
        # self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
        # Lunta.getScreenShot()

        #输入标题
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("如何年薪百万")
        #Action链模拟点击
        element=self.driver.find_element(By.XPATH,'//*[@id="article_post_submit"]')
        ActionChains(self.driver).move_to_element(element).click().perform()
        #提示帖子内容不能为空
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        Lunta.getScreenShot()

        # 不输入标题
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").clear()
        # Action链模拟点击
        element = self.driver.find_element(By.XPATH, '//*[@id="article_post_submit"]')
        ActionChains(self.driver).move_to_element(element).click().perform()
        # 提示输入标题不能为空
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
        Lunta.getScreenShot()

        self.driver.back()

